<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <title><spring:message code="message.lable.DICxiTongChaKan"/></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
							
    <section class="content-header">
        <h1><spring:message code="message.lable.DICxiTongChaKan"/></h1>
        <ol class="breadcrumb">
             <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.DicManage"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.sysDic"/></a></li>
        </ol>
    </section>
    
    <section class="content">
       <form action="${ctx}/dicSys/exportExcel.html" id="exportExcel" method="post" class="form-horizontal">
       <input id="fileName" name="fileName" type="hidden" value="<spring:message code="message.lable.syslistxls"/>" />
        <div class=" box box-success">
            <div class="box-body">
                <div class="input">
                	<div class="textalign1"><spring:message code="message.listForm.xiTongZiDianFenLeiMingCheng"/>：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="searchClassifyName" name="classifyName" placeholder="<spring:message code="message.listForm.xiTongZiDianFenLeiMingCheng"/>" maxlength="100" />
                    </div>
                    
                    <div class="textalign1"><spring:message code="message.listForm.xiTongZiDianFenLeiBianMa"/>：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="searchClassifyCode" name="classifyCode" placeholder="<spring:message code="message.listForm.xiTongZiDianFenLeiBianMa"/>" maxlength="20" />
                    </div>
                    
                    <div class="textalign1"><spring:message code="message.listForm.xiTongZiDianBianMa"/>：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="searchDicCode" name="dicCode" placeholder="<spring:message code="message.listForm.xiTongZiDianBianMa"/>" maxlength="20"  />
                    </div>
                </div>
                <div class="input">
                    <div class="textalign1"><spring:message code="message.listForm.xiTongZiDianMingCheng"/>：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="searchDicName" name="dicName" placeholder="<spring:message code="message.listForm.xiTongZiDianMingCheng"/>" maxlength="100" />
                    </div>
                     <%-- <div class="textalign1"><spring:message code="message.lable.status"/>：</div>
                    <div class="boxinput">
                        <select id="status" name="status" class="textinput">
                                  <option value="" ><spring:message code="message.select.option"/></option>
                                <option value="1" ><spring:message code="message.button.start"/></option>
                                <option value="0" ><spring:message code="message.button.stop"/></option>
                            </select>
                    </div> --%>
                    <div class="textalign" >
                           <button id="selectSys" type="button" class="btn btn-success btn-sm" onclick="search();"><spring:message code="message.button.seachSpacing"/></button>
                    </div>
                </div>
            
            
            </div>
          </div>
        </form>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        
        <div class=" box box-warning bottongroup">
             
            <%--  <ms:btn url="/dicSys/add.html"><label id="addNew" class="btn btn-default btn-sm"><spring:message code="message.button.addSpacing"/></label></ms:btn>
             <ms:btn url="/dicSys/enable.html"><label id="batchEnable" class="btn btn-default btn-sm" onclick="batchChangeStatus(1)"><spring:message code="message.button.startSpacing"/></label></ms:btn>
             <ms:btn url="/dicSys/disable.html"><label id="batchDisable" class="btn btn-default btn-sm" onclick="batchChangeStatus(0)"><spring:message code="message.button.stopSpacing"/></label></ms:btn> --%>
             <label onclick="exportExcel();" class="btn btn-default btn-sm"><spring:message code="message.lable.daoChu"/></label>
        </div>
  
		<div class="modal fade" id="dialog" tabindex="-1" >
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header bg-primary">
						<button type="button" class="close" data-dismiss="modal" ><span >&times;</span></button>
						<h5 class="modal-title"><spring:message code="message.lable.sysDic"/><span id="editTitle"><spring:message code="message.button.add"/></span></h5>
					</div>
					<div class="modal-body">
						
						<div class="form-group form-group-xs" style="width:50%;float:left;padding-right:10px;">
							<label for="pharCode" class=" control-label"><spring:message code="message.listForm.xiTongZiDianFenLeiBianMa"/>:</label>
							<input type="text" class="form-control" id="classifyCode" placeholder="<spring:message code="message.listForm.xiTongZiDianFenLeiBianMa"/>"  maxlength="10" >
						</div>
						
						<div class="form-group form-group-xs" style="width:50%;float:left;padding-left:10px;">
							<label for="pharCode" class=" control-label"><spring:message code="message.listForm.xiTongZiDianFenLeiMingCheng"/>:</label>
							<input type="text" class="form-control" id="classifyName" placeholder="<spring:message code="message.listForm.xiTongZiDianFenLeiMingCheng"/>"  maxlength="10">
						</div>
						
						<div class="form-group form-group-xs" style="width:50%;float:left;padding-right:10px;">
							<label for="pharCode" class=" control-label"><spring:message code="message.listForm.xiTongZiDianBianMa"/>:</label>
							<input type="text" class="form-control" id="dicCode" placeholder="<spring:message code="message.listForm.xiTongZiDianBianMa"/>" maxlength="10">
						</div>
						<div class="form-group form-group-xs" style="width:50%;float:left;padding-left:10px;">
							<label for="pharName" class=" control-label"><spring:message code="message.listForm.xiTongZiDianMingCheng"/>:</label>
							<input type="text" class="form-control" id="dicName" placeholder="<spring:message code="message.listForm.xiTongZiDianMingCheng"/>" maxlength="50">
						</div>
						<div class="form-group form-group-xs">
							<label for="pharName" class=" control-label"><spring:message code="message.lable.remark"/>:</label>
							<textarea rows="3" cols="" class="form-control" id="remark" placeholder="<spring:message code="message.lable.remark"/>" maxlength="256"></textarea>
						</div>
						
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary btn-sm" onclick="saveDicSys();"><spring:message code="message.button.saveSpacing"/></button>
						<button type="button" class="btn btn-danger btn-sm" id="close" data-dismiss="modal"><spring:message code="message.button.closeSpacing"/></button>
					</div>
				</div>
			</div>
		</div>

    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
    
    //绑定回车
    $('#searchClassifyCode,#searchClassifyName,#searchDicCode,#searchDicName,#status').bind('keydown', function(event) {
        if (event.keyCode == "13") {    // 13 位电脑上回车键的位置代码
            $('#selectSys').click();
        }
    }); 
  
    $("#searchClassifyName").focus();//加载页面光标在企业资质类型名称上
    
	    function validateRep(){
		    var classifyCode = $("#classifyCode");
			var classifyName = $("#classifyName");
		     $.post("validateRep.html", {
				classifyCode:classifyCode,
				classifyName:classifyName
			}, function(result) {
				if (result.classifyCode) {
					$.alert("<spring:message code="message.listForm.xiTongZiDianFenLeiBianMa"/><spring:message code="message.lable.yiChunZai"/>", "warn");
				} 
				if(result.classifyName){
					$.alert("<spring:message code="message.listForm.xiTongZiDianFenLeiMingCheng"/><spring:message code="message.lable.yiChunZai"/>", "warn");
				}
			}, "json");
		}
    	var sysDicId = "";
   
    	function batchChangeStatus(status) {
    		var msg = "<spring:message code="message.button.stop"/>";
    		var url = "${ctx}/dicSys/enable.html"; 
    		if(status == 1){
    			msg = "<spring:message code="message.button.start"/>";
    			url = "${ctx}/dicSys/disable.html";
    		}
    		var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
    		if (rowIds.length <= 0) {
    			$.alert("<spring:message code="message.lable.pleaseSelect"/>"+msg+"<spring:message code="message.listForm.ziDian"/>", "warn");
    			return;
    		}
    		
    		var data = "";
			var list = [];
			for(var i = 0;i<rowIds.length;i++){
				var sta =  $("#gridlist").jqGrid('getRowData',rowIds[i]);
				if(sta.status != msg){
					var dicName = sta.dicName;
					
					data += dicName+",";
					list.push({"sysDicId":rowIds[i], "status":status});
				}else{
					
				}  
			}
			if(data){
				data = data.substring(0,data.length-1);
			}else{
				$.alert("<spring:message code="message.lable.pleaseSelect"/>"+msg+"<spring:message code="message.lable.OKData"/>", "warn");
				return;
			}
    		
    		$.HN.message.confirm("<spring:message code="message.lable.OKYES"/>"+msg+"<spring:message code="message.lable.FlowerDataYESorNo"/><br/>"+data, '', '').on(function (e) {
                if (e) {
    		
    		$.post(url, {
    			"array" : json.jsonToString(list)
    		}, function(result) {
    			if (result.success) {
    				var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
    				search(curpage);
    				$.alert("<spring:message code="message.HN.alert.chengGongCaoZuo"/>"+result.conditions.sum+"<spring:message code="message.HN.alert.tiaoShuJu"/>", "success");
    			} else {
    				$.alert(result.msg || "<spring:message code="message.HN.alert.fail"/>", "error");
    			}
    		}, "json");
                }
    		}); 
    	}
    
    	function saveDicSys() {
    		var params = {"sysDicId":sysDicId};
    		
    		var classifyCode = $.trim($("#classifyCode").val());
    		if (classifyCode == null || classifyCode == "") {
    			$("#classifyCode").trigger("focus");
                $.alert("<spring:message code="message.yanZheng.qingShuRu"/><spring:message code="message.listForm.xiTongZiDianFenLeiBianMa"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
    			return;
    		} else if (!/^[a-zA-Z0-9_]+$/.test(classifyCode)) {
    			$("#classifyCode").trigger("focus");
                $.alert("<spring:message code="message.listForm.xiTongZiDianFenLeiBianMa"/><spring:message code="message.yanZheng.zhiNengYouZiMuShuZiZuCheng"/>", "warn");
    			return;
    		} else if(classifyCode.length>20){
                $("#classifyCode").trigger("focus");
                $.alert("<spring:message code="message.listForm.xiTongZiDianFenLeiBianMa"/><spring:message code="message.yanZheng.changDuGuoChang"/>", "warn");
                return;
            } else {
    			params["classifyCode"] = classifyCode;
    		}
    		
    		var classifyName = $.trim($("#classifyName").val());
    		
    		if (classifyName == null || classifyName == "") {
    			$("#classifyName").trigger("focus");
                $.alert("<spring:message code="message.yanZheng.qingShuRu"/><spring:message code="message.listForm.xiTongZiDianFenLeiMingCheng"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
    			return;
    		} else if(classifyName.length>100){
                $("#classifyName").trigger("focus");
                $.alert("<spring:message code="message.listForm.xiTongZiDianFenLeiMingCheng"/><spring:message code="message.yanZheng.changDuGuoChang"/>", "warn");
                return;
            } else {
    			params["classifyName"] = classifyName;
    		}
    		
    		var dicCode = $.trim($("#dicCode").val());
    		if (dicCode == null || dicCode == "") {
    			$("#dicCode").trigger("focus");
                $.alert("<spring:message code="message.yanZheng.qingShuRu"/><spring:message code="message.listForm.xiTongZiDianBianMa"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
    			return;
    		} else if (!/^[a-zA-Z0-9_]+$/.test(dicCode)) {
    			$("#dicCode").trigger("focus");
                $.alert("<spring:message code="message.listForm.xiTongZiDianBianMa"/><spring:message code="message.yanZheng.zhiNengYouZiMuShuZiZuCheng"/>", "warn");
    			return;
    		} else if(dicCode.length>20){
                $("#dicCode").trigger("focus");
                $.alert("<spring:message code="message.listForm.xiTongZiDianBianMa"/><spring:message code="message.yanZheng.changDuGuoChang"/>", "warn");
                return;
            }  else {
    			params["dicCode"] = dicCode;
    		}
    		
    		var dicName = $.trim($("#dicName").val());
    		if (dicName == null || dicName == "") {
    			$("#dicName").trigger("focus");
                $.alert("<spring:message code="message.yanZheng.qingShuRu"/><spring:message code="message.listForm.xiTongZiDianMingCheng"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
    			return;
    		} else if(dicName.length>100){
                $("#dicName").trigger("focus");
                $.alert("<spring:message code="message.listForm.xiTongZiDianMingCheng"/><spring:message code="message.yanZheng.changDuGuoChang"/>", "warn");
                return;
            }  else {
    			params["dicName"] = dicName;
    		}
    		var remark = $.trim($("#remark").val());
    		params["remark"] = remark;
    		
    		$.HN.message.confirm("<spring:message code="message.HN.alert.OkSaveYESorNO"/>", '', '').on(function (e) {
                if (e) {
    		
                	var url = "${ctx}/dicSys/add.html";
                    if(sysDicId !=null && sysDicId != ""){ 
                    	url = "${ctx}/dicSys/edit.html";      
                    }
                	
                	$.post(url, params, function(result) {
            			if (result.success) {
            				$("#close").trigger("click");
            				var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
            				search(curpage);
            				$.alert("<spring:message code="message.HN.alert.success"/>", "success");
            			} else {
            				$.alert(result.msg || "<spring:message code="message.HN.alert.fail"/>", "error");
            			}
            		}, "json");
            		
                }
    		}); 
    		
    	}
    
    	function cleanForm() {
    		
    		$("#rootType").val("");
    		$("#dicPhar1").val("");
    		$("#dicPhar2").val("");
    		$("#dicPhar1 option:not(:first)").remove();
    		$("#dicPhar2 option:not(:first)").remove();
    		$("#pharCode").val("");
			$("#pharName").val("");
    	}
    
    	function edit(id) {
    		sysDicId = id || "";
    		cleanForm();
    		$.post("initEdit.html", {
    			id : id
    		},
    		 		
    		function(result) {
    			if (result.success) {
    				var obj = result.rows;
    				$('.modal-title').html('<spring:message code="message.lable.DICxiTongBianJi"/>');
    				$("#classifyCode").val(obj.classifyCode);
    				$("#classifyName").val(obj.classifyName);
    				$("#dicCode").val(obj.dicCode);
    				$("#dicName").val(obj.dicName);
    				$("#remark").val(obj.remark);
    				$('#dialog').modal({
                        keyboard: true
                    });
    			}
    			
    		}, "json");
    	}
    	
    	function search(page) {
    		var status = $("#status").val();
    		var classifyCode = $("#searchClassifyCode").val();
    		var classifyName = $("#searchClassifyName").val();
    		var dicCode = $("#searchDicCode").val();
    		var dicName = $("#searchDicName").val();
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{"classifyCode":classifyCode, "classifyName":classifyName, "dicCode":dicCode, "dicName":dicName,"status":status},
    	        page : (page || 1)
    	    }).trigger("reloadGrid"); //重新载入  
    	}
    
        $(function () {
            $('#addNew').click(function () {
            	$('.modal-title').html('<spring:message code="message.lable.DICxiTongXinZeng"/>');
            	sysDicId = "";
				$("#classifyCode").val("");
				$("#classifyName").val("");
				$("#dicCode").val("");
				$("#dicName").val("");
				$("#remark").val("");
				$("#status").val("");
                $('#dialog').modal({
                    keyboard: true
                });
            });
            $("#gridlist").jqGrid({
                url: "getDicSysList.html",
                mtype: "post",
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: [
                    'id',
                    '<spring:message code="message.jqGrid.cz"/>',
					'<spring:message code="message.listForm.xiTongZiDianFenLeiBianMa"/>', 
					'<spring:message code="message.listForm.xiTongZiDianFenLeiMingCheng"/>', 
					'<spring:message code="message.listForm.xiTongZiDianBianMa"/>', 
					'<spring:message code="message.listForm.xiTongZiDianMingCheng"/>', 
					'<spring:message code="message.lable.remark"/>',
					//'更新人',
					//'更新时间',
					'<spring:message code="message.lable.status"/>'
					
                ],
                colModel: [
                    { name: 'sysDicId', width: 10,hidden:true, align:"center", sortable: false},  
                    { name: 'operate', width: 4, hidden:true, align:"center", sortable: false,
                        formatter : function(val, opts, rowdata) {
                            var str =  "<ms:btn url='/dicSys/edit.html'><a href='javascript:edit(\""+rowdata.sysDicId+"\");' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat 0px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.bianJi"/>'></a></ms:btn>";
                            str += "<ms:btn url='/dicSys/log.html'><a href='log.html?id="+rowdata.sysDicId+"&dicCode="+rowdata.dicCode+"&dicName="+rowdata.dicName+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -120px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.weiHuJiLu"/>'></a></ms:btn>";
                            return str;
                             }
                    },
                    { name: 'classifyCode', width: 7, align:"center", sortable: false},
                    { name: 'classifyName', width: 12, align:"center", sortable: false },
                    { name: 'dicCode', width: 7, align:"center", sortable: false},
                    { name: 'dicName', width: 12, align:"center", sortable: false},
                    { name: 'remark', width: 8, align: 'center', sortable: false},
                  //  { name: 'updUser', width: 10, align: 'center', sortable: false},
                   // { name: 'updDatetime', width: 10, align: 'center', sortable: false},
                    { name: 'status', hidden:true, index: 'status', width: 4, align: 'center', sortable: false,
                    	cellattr:function (rowId, val, rawObject, cm) {
                            if(val == '停用'){
                                return 'style="color:red"';
                            }
                        },
                        formatter : function(val, opts, rowdata) {
                            var strSta = "";
                            if(rowdata.status == 1){
                                strSta += "<spring:message code="message.button.start"/>";
                            }else{
                                strSta += "<spring:message code="message.button.stop"/>";
                            }
                            return strSta;
                        }
                    }
                    
                ],
                rowNum: 20,
                rowList: [10, 20, 50,100],
                rownumbers: true,
                pager: "#gridpage",
                //multiselect: true, 
                viewrecords: true,
                caption: "<spring:message code="message.list.sysDiclist"/>",
              //序号宽度自动变化
                gridComplete:function(){        
                    var page = $("#gridlist").jqGrid('getGridParam','page');
                    var rows = $('#gridlist').getGridParam("rowNum");
                    var maxnum = (rows*page).toString();
                    var len = (maxnum.length)*10;
                    $('.jqgfirstrow').find('td').eq(0).css('width',len+'px');
                    $('#gridlist_rn').css('width',len+'px');
                    
                  //单条数据自动选中
                	var rowIds = $("#gridlist").jqGrid('getDataIDs');
                	if(rowIds.length==1){
                		$("#"+rowIds[0]).click();
                	}
                },
                jsonReader: {
                	repeatitems: false,
                    id: "sysDicId"
                }
            });
            
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            
            $(window).trigger("resize");
          
          
        });
     	function exportExcel(){
     		$.HN.message.confirm('<spring:message code="message.lable.OKExport"/>&nbsp;<spring:message code="message.lable.syslistxls"/>&nbsp;<spring:message code="message.lable.ma"/>', '', '').on(function (e)  {
	               if (e) {
	            	  $("#exportExcel").submit();
			
	               }
          	 }); 
          	
     	}
    </script>
</body>
</html>



